﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace CapstoneMockup
{
    public partial class CreateExpensePage : PhoneApplicationPage
    {
        public CreateExpensePage()
        {
            InitializeComponent();
        }

        private void NewExpense_Click(object sender, RoutedEventArgs e)
        {
            if (AmountOfPurchase.Text != "" || Description.Text != "")
            {
                try
                {
                    double amount = Convert.ToDouble(AmountOfPurchase.Text);
                    App.ViewModel.User._currentLog.AddExpenseToList(
                        Description.Text, amount, AccountNumber.Text,
                        PlaceOfPurchase.Text);

                    if (App.ViewModel.User._currentLog != null)
                        if (NavigationService.CanGoBack) { }
                    NavigationService.GoBack();
                }
                catch (FormatException)
                {
                    ErrorBlock.Text = "You did not enter the information in its correct form";
                }

            }
            else
            {
                ErrorBlock.Text = "Enter in the required information";
            }
        }
    }
}